package com.example.swagger.config;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.security.OAuthFlow;
import io.swagger.v3.oas.annotations.security.OAuthFlows;
import io.swagger.v3.oas.annotations.security.OAuthScope;
import io.swagger.v3.oas.annotations.security.SecurityScheme;

// 使用注解的方式配置 OpenAPI
@OpenAPIDefinition(info = @Info(title = "Foo API",
        description = "Foo description", version = "v1"))
// 配置 OpenAPI 文档接口安全认证
@SecurityScheme(name = "security_auth", type = SecuritySchemeType.OAUTH2,
        flows = @OAuthFlows(authorizationCode = @OAuthFlow(
                authorizationUrl = "${springdoc.oAuthFlow.authorizationUrl}"
                , tokenUrl = "${springdoc.oAuthFlow.tokenUrl}", scopes = {
                @OAuthScope(name = "springdoc.read", description = "read scope"),
                @OAuthScope(name = "springdoc.write", description = "write scope") })))
public class OpenApiDemoConfig {
}


// 使用注解配置 OpenAPI 相当于 代码配置 OpenAPI，注解的配置方式更加简洁，更加直观。
// 来源参考 springdoc-openapi 官方示例 https://github.com/springdoc/springdoc-openapi-demos/blob/master/demo-oauth2/oauth-resource-server-webmvc/src/main/java/org/springdoc/demo/resource/config/OpenApiConfig.java